from kafka import KafkaConsumer

# 1、创建消费者
consumer = KafkaConsumer(
    bootstrap_servers='master:9092',
    group_id='asdasdasd',
    auto_offset_reset="earliest"  # earliest：从最早的消息开始消费，latest：从最新的消息开始消费
)

# 订阅topic
consumer.subscribe(topics=["shujia"])

while True:
    # 拉取数据
    data = consumer.poll(timeout_ms=1000)
    for lines in data.values():
        for line in lines:
            topic = line.topic
            partition = line.partition
            offset = line.offset
            timestamp = line.timestamp
            value = line.value
            print(topic, partition, offset, timestamp, value)
